package com.tac.controller;

import com.tac.common.result.Result;
import com.tac.pojo.Cart;
import com.tac.pojo.vo.Change;
import com.tac.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping("/cart")
@RestController
@Api(value = "购物车" ,tags = "购物车")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 添加  还需要判断一下购物车里是否已经有了有了的话直接加数量
     * @return
     */
    @PostMapping("/inserte/{pid}")
    @ApiOperation("添加购物车")
    public Result inserte(@PathVariable Integer pid){
        return cartService.inserte(pid);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation("根据id删除")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
      return   cartService.deleteById(id);
    }

    /**
     * 修改数量及价格
     * @param
     * @param change
     * @return
     */
    @ApiOperation("修改数量及价格")
    @PutMapping("/updateById/{cartid}")
    public Result updateById(@PathVariable Integer cartid,@RequestBody Change change){
        return cartService.updateById(cartid,change);
    }

    /**
     * 选中
     * @param cartid
     * @return
     */
    @ApiOperation("选中status=1是选中，0是不选中")
    @PutMapping("/updateByIdAndStatus")
    public Result updateByIdAndStatus(Integer cartid,Integer status){
        return  cartService.updateByIdAndStatus(cartid,status);
    }

    /**
     * 全部选中
     * @param status
     * @return
     */
    @ApiOperation("全部选中status=1是选中，0是不选中")
    @PutMapping("/updateByIdAndStatusAll")
    public Result updateByIdAndStatusAll( Integer status){
        return cartService.updateByIdAndStatusAll(status);
    }

    /**
     * 根据用户id查看购物车
     * @param
     * @return
     */
    @GetMapping("/selectByUid")
    @ApiOperation("根据用户id查看购物车")
    public Result<List<Cart>> selectByUid(){
        return cartService.selectByUid();
    }
}

